package com.app.service.impl;

import com.app.entity.Feedback;
import com.app.mapper.FeedbackMapper;
import com.app.service.FeedbackService;
import com.app.util.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zxy
 * @since 2021-04-07
 */
@Service
public class FeedbackServiceImpl extends ServiceImpl<FeedbackMapper, Feedback> implements FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public Result addFeedback(Feedback feedback) {
        feedback.setCreateTime(new Date());
        feedbackMapper.insert(feedback);
        return Result.success();
    }

    @Override
    public Result findFeedbackAdmin() {
        return Result.success(feedbackMapper.selectList(new QueryWrapper<Feedback>().orderByDesc("create_time")));
    }

    @Override
    public Result updateFeedbackAdmin(Integer id) {
        Feedback feedback = new Feedback();
        feedback.setId(id);
        feedback.setState(1);
        feedbackMapper.updateById(feedback);
        return Result.success();
    }
}
